﻿namespace Sgr.AspNetCore
{
    /// <summary>
    /// Results 扩展方法
    /// </summary>
    public static class ResultsExtensions
    {
        /// <summary>
        /// URL已过期
        /// </summary>
        /// <param name="context">HTTP上下文</param>
        /// <returns>错误响应结果</returns>
        public static IResult ExpiredUrl(HttpContext context)
        {
            ArgumentNullException.ThrowIfNull(context);

            return Results.Problem(
                statusCode: StatusCodes.Status400BadRequest,
                title: "Invalid Request",
                type: ProblemTypes.Validation,
                detail: "URL已过期",
                instance: context.Request.Path);
        }

        /// <summary>
        /// 签名无效
        /// </summary>
        /// <param name="context">HTTP上下文</param>
        /// <returns>错误响应结果</returns>
        public static IResult InvalidSignature(HttpContext context)
        {
            ArgumentNullException.ThrowIfNull(context);

            return Results.Problem(
                statusCode: StatusCodes.Status400BadRequest,
                title: "Invalid Request",
                type: ProblemTypes.Validation,
                detail: "签名无效",
                instance: context.Request.Path);
        }

        /// <summary>
        /// 对象不存在的错误响应
        /// </summary>
        /// <param name="context">HTTP上下文</param>
        /// <returns>错误响应结果</returns>
        public static IResult ObjectNotFound(HttpContext context)
        {
            ArgumentNullException.ThrowIfNull(context);

            return Results.Problem(
                statusCode: StatusCodes.Status404NotFound,
                title: "Not Found",
                type: ProblemTypes.NotFound,
                detail: "对象不存在",
                instance: context.Request.Path);
        }
    }
}